// packageA/pages/hangqingList/hangqingList.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab2: ['日评', '周评', '月评'],
    tab1Active: 0,
    tab2active: 0,
    intCurrPage: 1,
    serachInputValue: '',
    indexList: [],
    isMore: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
   
    await this.queryType()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var that = this,
    ag = app.globalData
  //定义导航
  that.setData({
    navHeight: ag.navHeight, //导航栏高度
    navTop: ag.navTop, //导航栏距顶部距离
    navObj: ag.navObj, //胶囊的高度
    navObjWid: ag.navObjWid, //胶囊宽度+距右距离
    tabbarHeight: ag.tabbarHeight, //tabbar高度
    windowHeight: ag.windowHeight, //窗口高度
    screenHeight: ag.screenHeight, // 屏幕高度
    statusBarHeight: ag.statusBarHeight, //状态栏
    // stickylistHeight: ag.screenHeight - ag.statusBarHeight - ag.navHeight
    stickylistHeight: ag.screenHeight - ag.navHeight - 75-15,
    // stickylistHeight: ag.windowHeight - ag.navHeight - 38 - 35 + 10 + ag.tabbarHeight
  })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage() {

  // },

  onShareAppMessage(e) {
    console.log(e)
    return {
      title:e.target.dataset.title,
      path:'/packageA/pages/hangqingList/hangqingList'
    }
    const promise = new Promise(resolve => {
      setTimeout(() => {
        resolve({
          title: '自定义转发标题'
        })
      }, 2000)
    })
    return {
      title: '自定义转发标题',
      path: '/page/user?id=123',
      promise 
    }
  },


  goback() {
    wx.navigateBack({
      delta: 0,
    })
  },
  // 查询分类
  queryType(e) {
    app.getDaoPost('api/FeijiuApp/Feijiu_BJ_Get_bwClass', {}, r => {
      console.log(r, '===分类')
      if (r.code == 200) {
        this.setData({
          tab1: r.data.classid
        }, () => {
          this.queryIndex()
        })
      }
    })
  },
  // 查询列表
  queryIndex() {
    wx.showLoading({
      title: '数据加载中',
    })
    let input = {
        key: this.data.serachInputValue,
        types: this.data.tab2active + 1,
        classid: this.data.tab1[this.data.tab1Active].ClassIndex,
        intCurrPage: this.data.intCurrPage,
        intPageSize: 15,
      },
      that = this
    app.getDaoPost('api/FeijiuApp/Feijiu_BJ_Get_bwList', input, r => {
      wx.hideLoading()
      console.log(r, '行情分析列表')
      if (r.code == 200) {
        if (r.data.data.ds.length >= 15) {
          that.setData({
            indexList: [...that.data.indexList, ...r.data.data.ds],
            isMore: true,
            intCurrPage: that.data.intCurrPage + 1
          })

        } else {
          that.setData({
            indexList: [...that.data.indexList, ...r.data.data.ds],
            isMore: false,
            intCurrPage: that.data.intCurrPage
          })
        }
      } else {
        wx.showToast({
          title: r.message,
          icon: 'none'
        })
      }
    })
  },
  //跳转H5
  jumpweb(e) {
    let weburl = e.currentTarget.dataset.url
    console.log(weburl)
    // wx.navigateTo({
    //   url: `../other/web?url=${weburl}`
    // })
    wx.navigateTo({
      url: '/pages/other/web',
      success: function (res) {
        // 通过 eventChannel 向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          url: weburl
        })
      }
    })
  },
  //监听搜索输入框
  serachInput(e) {
    this.setData({
      serachInputValue: e.detail.value
    })
  },
  //tab1切换
  changeTuijian(e) {
    this.setData({
      tab1Active: e.currentTarget.dataset.index,
      classid: e.currentTarget.dataset.classid,
      intCurrPage: 1,
      indexList: [],
      isMore: true
    }, () => {
      this.queryIndex()
    })
  },
  //tab2切换
  cilckSahngjiTuijian(e) {
    this.setData({
      tab2active: e.currentTarget.dataset.index,
      intCurrPage: 1,
      indexList: [],
      isMore: true
    }, () => {
      this.queryIndex()
    })
  },
  // 搜索
  toSearch(e) {
    this.setData({
      intCurrPage: 1,
      indexList: [],
      isMore: true
    }, () => {
      this.queryIndex()
    })
  },
  //触底加载更多
  indexListMore(e) {
    console.log(e, '触底')
    if (this.data.isMore == true) {
      this.queryIndex()
    } else {
      wx.showToast({
        title: '暂时没有更多啦',
        icon: 'none'
      })
    }
  },
  //分享
//   hangqingShare(e) {
// console.log('===',e)
//   }
})